
using System;
using System.Collections.Generic;
using Abp.Application.Services;
using Abp.Domain.Repositories;
using L._52ABP.Common.Extensions.Enums;

using LTMCompanyName.YoyoCmsTemplate.DataExporting.Excel.Epplus;
using LTMCompanyName.YoyoCmsTemplate.DataFileObjects.DataTempCache;
using LTMCompanyName.YoyoCmsTemplate.Dtos;
using LTMCompanyName.YoyoCmsTemplate.Exam.Dtos;


namespace LTMCompanyName.YoyoCmsTemplate.Exam.Exporting
{
    /// <summary>
    /// 答题记录的视图模型根据业务需要可以导出为Excel文件
    /// </summary>
	[RemoteService(IsEnabled = false)]
    public class StockSubmitListExcelExporter : EpplusExcelExporterBase, IStockSubmitListExcelExporter
    {
        /// <summary>
        /// 构造函数，需要继承父类
        /// </summary>
        /// <param name="dataTempFileCacheManager"></param>
        public StockSubmitListExcelExporter(IDataTempFileCacheManager dataTempFileCacheManager) : base(dataTempFileCacheManager)
        {

        }
        public FileDto ExportToExcelFile(List<StockSubmitListDto> stockSubmitListDtos, IRepository<StockCategory, long> _stockCategoryRepository)
        {

            var fileExportName = L("StockSubmitList") + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";

            var excel =
                 CreateExcelPackage(fileExportName, excelpackage =>
               {
                   var sheet = excelpackage.Workbook.Worksheets.Add(L("StockSubmits"));

                   sheet.OutLineApplyStyle = true;
                   AddHeader(sheet, L("CreationTime"), L("StockCategoryName"), L("StudentName"), L("className"), L("TotalScore"), L("StockScore"), L("QuestionCount"), L("AnswerRightCount"), L("UseTime"));
                   AddObject(sheet, 2, stockSubmitListDtos
                    , ex => ex.CreationTime.ToString("G")
                    ,ex => _stockCategoryRepository.Get(ex.StockId)?.Name
                    , ex => ex.StudentName
                    , ex => ex.ClassName
                    , ex => ex.TotalScore
                    , ex => ex.StockScore
                    , ex => ex.QuestionCount
                    , ex => ex.AnswerRightCount
                    , ex => ex.UseTime
                          );

                   //// custom codes

                   //Formatting cells
                   var UpdatetimeColumn = sheet.Column(7);
                   for (var i = 1; i <= 7; i++)
                   {
                       sheet.Column(i).AutoFit();
                   }
                   //// custom codes end
               });
            return excel;
        }
    }
}
